package com.thank.concurrency.samples.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.thank.concurrency.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 演示Guava下的不可变集合构造
 */
@Slf4j
@ThreadSafe
public class ImmutableExample3 {

    private static final List<Integer> list = ImmutableList.of(1, 2, 3);
    private static final ImmutableSet<Integer> set = ImmutableSet.copyOf(list);
    private static final Map<Integer, Integer> map = ImmutableMap.of(1, 10, 2, 20);
    private static final Map<Integer, Integer> map2 = ImmutableMap.<Integer, Integer>builder()
            .put(1, 10).build();

    public static void main(String[] args) {
        // 编译通过, 但是修改值会抛出UnsupportedOperationException
        map.put(1, 100);
    }
}
